import wx
import wx.aui


class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        super(MyFrame, self).__init__(parent, title=title, size=(800, 600))
        panel = wx.Panel(self)

        notebook = wx.aui.AuiNotebook(panel, style=wx.aui.AUI_NB_TOP)

        self.page1 = self.create_page(notebook, "页面 1")
        self.page2 = self.create_page(notebook, "页面 2")
        self.page3 = self.create_page(notebook, "页面 3")

        notebook.AddPage(self.page1, "页面 1")
        notebook.AddPage(self.page2, "页面 2")
        notebook.AddPage(self.page3, "页面 3")

        self.Bind(wx.EVT_CLOSE, self.OnClose)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(notebook, 1, wx.EXPAND)
        panel.SetSizer(sizer)
        self.SetSizer(wx.BoxSizer(wx.VERTICAL))
        self.GetSizer().Add(panel, 1, wx.EXPAND)

        self.Centre()

    def OnClose(self,event):
        self.Destroy()

    def on_page1_button(self,event):
        wx.MessageBox("我是页面1")

    def on_page3_button(self,event):
        static_text = self.page3.static_text
        static_text.SetLabel("我是页面3")

    def create_page(self, notebook, label):
        page = wx.Panel(notebook)
        if label == "页面 1":
            button = wx.Button(page, label="显示消息", pos=(10, 10))
            button.Bind(wx.EVT_BUTTON, self.on_page1_button)
        elif label == "页面 2":
            static_text = wx.StaticText(page, label="我是页面2", pos=(10, 10))
        elif label == "页面 3":
            static_text = wx.StaticText(page, label="", pos=(10, 10))
            page.static_text = static_text
            button = wx.Button(page, label="更新标签", pos=(100, 10))
            button.Bind(wx.EVT_BUTTON, self.on_page3_button)

        return page

app = wx.App(False)
frame = MyFrame(None, 'AuiNotebook')
frame.Show(True)
app.MainLoop()
